package rss;

import java.net.URL;
import java.util.Vector;

public class FeedPoller implements Runnable {

	private Vector<URL> urls;
	private int sleepMillis;
	private boolean finish;
	private ArticleLoadedListener listener;
	
	public FeedPoller(ArticleLoadedListener listener) {
		this(new Vector<URL>(), 300000, listener);
	}
	
	public FeedPoller(Vector<URL> urls, int sleepMillis, ArticleLoadedListener listener) {
		this.urls = urls;
		this.sleepMillis = sleepMillis;
		this.listener = listener;
		this.finish = false;
	}
	
	@Override
	public void run() {
		while(!finish) {
			Article.parseArticles(urls, listener);
			
			try {
				Thread.sleep(sleepMillis);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
	}

	public Vector<URL> getUrls() {
		return urls;
	}

	public void setUrls(Vector<URL> urls) {
		this.urls = urls;
	}

	public int getSleepMillis() {
		return sleepMillis;
	}

	public void setSleepMillis(int sleepMillis) {
		this.sleepMillis = sleepMillis;
	}

	public boolean isFinish() {
		return finish;
	}

	public void setFinish(boolean finish) {
		this.finish = finish;
	}

	public ArticleLoadedListener getListener() {
		return listener;
	}
	
	public void setListener(ArticleLoadedListener listener) {
		this.listener = listener;
	}
}